home *** CD-ROM | disk | FTP | other *** search
- 'general section
- Declare Function GetPrivateProfileInt% Lib "Kernel" (ByVal lpApplicationName$, ByVal lpKeyName$, ByVal nDefault%, ByVal lpFileName$)
- Declare Function GetPrivateProfileString% Lib "Kernel" (ByVal lpApplicationName$, ByVal lpKeyName As Any, ByVal lpDefault$, ByVal lpReturnedString$, ByVal nSize%, ByVal lpFileName$)
- Declare Function WritePrivateProfileString% Lib "Kernel" (ByVal lpApplicationName$, ByVal lpKeyName$, ByVal lpString$, ByVal lplFileName$)
-
- 'Call the Crypt routine again the decrypt the Strg$. Without the proper
- 'Pass$, you'll get garbage back. The longer the password, the longer it
- 'takes to "number crunch" to figure out the password.
-
- Dim Pass$
- Dim Strg$
- Dim H$
-
- Sub Command1_Click ()
- Pass$ = "PASSWORD"
- Strg$ = "You won't crack this easily"
-
- Print "Original = "; Strg$
- Call Crypt(Pass$, Strg$)
-
- Print "Encrypted = "; Strg$
-
- 'When writing an encrypted password to a sequential access file like the
- 'INI files, you need to convert the resultant encrypted file to hex data.
- 'This is because you can end up with an encrypted password that contains
- 'characters which cannot be properly read using sequential access. So,
- 'before saving your encrypted password, use this routine:
-
- H$ = ""
- For i = 1 To Len(Strg$)
- J$ = Hex$(Asc(Mid$(Strg$, i, 1)))
- If Len(J$) = 1 Then J$ = "0" + J$
- H$ = H$ + J$
- Next
-
- Print "Hex = "; H$
-
- 'This will create a string like "0EF31105" or some such. Save that to
- 'the INI file.
-
- 'Store the LENGTH of the password string as 2 bytes and concatenate
-
- H$ = Format$(Len(H$), "00") + H$
- x% = WritePrivateProfileString%("SECURITY", "PASSWORD", H$, "E:\PROJECT.INI")
-
- End Sub
-
- Sub Command2_Click ()
- 'To read it back in,
- H$ = Space$(80)
- x% = GetPrivateProfileString%("SECURITY", "PASSWORD", "PASSWORD", H$, Len(H$), "E:\PROJECT.INI")
- Print "After INI read = "; H$
-
- 'PASSWORD=160000000000000000
-
- H$ = Mid$(H$, 3, Val(Left$(H$, 2)))
-
- Print "Before hex conversion = "; H$
-
- Strg$ = ""
- For i = 1 To Len(H$) Step 2
- J$ = Mid$(H$, i, 2)
- Strg$ = Strg$ + Chr$(Val("&H" + J$))
- Next
- Print "After hex conversion = "; Strg$
-
- 'Strg$ would then contain the encrypted string, which you can now
- 'decrypt.
-
- Call Crypt(Pass$, Strg$)
- Print "Decrypted = "; Strg$
- End Sub
-
- Sub Crypt (Pass$, Strg$)
- a = 1
- For i = 1 To Len(Strg$)
- B = Asc(Mid$(Pass$, a, 1)): a = a + 1: If a > Len(Pass$) Then a = 1
- Mid$(Strg$, i, 1) = Chr$(Asc(Mid$(Strg$, i, 1)) Xor B)
- Next
- End Sub
-